package com.javasm.controller.B2CController;

import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.javasm.common.http.AxiosResult;
import com.javasm.common.util.DownloadUtils;
import com.javasm.common.util.ExportExcelUtil;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.orderCriteria.OrderGoodsCriteria;
import com.javasm.domin.entity.orderEntity.B2cOrder;
import com.javasm.domin.entity.orderEntity.B2cOrderGoods;
import com.javasm.domin.vo.orderVo.OrderAndReceiver;
import com.javasm.domin.vo.orderVo.OrderExcelVo;
import com.javasm.domin.vo.orderVo.OrderGoodVo;
import com.javasm.mapper.B2cOrderMapper.OrderGoodsMapper;
import com.javasm.service.B2cOrderService.ExportService;
import com.javasm.service.B2cOrderService.OrderGoodsService;
import com.javasm.service.B2cOrderService.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/11/22-11:37
 * @Since:jdk1.8
 * @Description:
 */
@RestController
@RequiredArgsConstructor
@Slf4j
public class ReportExcelController extends BaseController {
//    private final ExportService exportService;
//    private final OrderService orderService;
//    private final OrderGoodsService orderGoodsService;
//
//    @RequestMapping(value = "/order/excel/{idList}")
//    public AxiosResult<Boolean> ExcelExpport(@PathVariable List<Serializable> idList, OrderGoodsCriteria orderGoodsCriteria, HttpServletResponse response) {
//
//        FileOutputStream fileOutputStream = null;
//        int j = 0;
//        Random random = new Random();
//        for (int i = 0; i < 10000; i++) {
//            // 生成 0-9 随机整数
//            int number = random.nextInt(1000);
//            j = number;
//        }
//        try {
//            List<OrderAndReceiver> byIdList = orderService.findByIdList(idList);
//            orderGoodsCriteria.setOrderIdList(idList);
//            List<OrderGoodVo> orderGoodByOrderIdList = orderGoodsService.findOrderGoodByOrderIdList(orderGoodsCriteria);
//
//            File file = new File("C:\\Users\\Administrator\\Desktop\\" + j + "订单信息表.xls");
//            fileOutputStream = new FileOutputStream(file);
//            SXSSFWorkbook workbook = new SXSSFWorkbook(100);
//            Sheet sheet = workbook.createSheet("订单表");
//            //创建行
//            Row titleRow = sheet.createRow(0);
//            //2.此行创建标题列
//            Cell cell = titleRow.createCell(0);
//
//            cell.setCellValue("订单编号");
//            cell = titleRow.createCell(1);
//            cell.setCellValue("订单类型");
//            cell = titleRow.createCell(2);
//            cell.setCellValue("业务类型");
//            cell = titleRow.createCell(3);
//            cell.setCellValue("订单动作");
//            cell = titleRow.createCell(4);
//            cell.setCellValue("订单状态");
//            cell = titleRow.createCell(5);
//            cell.setCellValue("下单日期");
//
//            cell = titleRow.createCell(6);
//            cell.setCellValue("收货人姓名");
//            cell = titleRow.createCell(7);
//            cell.setCellValue("收货人地址");
//            cell = titleRow.createCell(8);
//            cell.setCellValue("收货人电话");
//            cell = titleRow.createCell(9);
//            cell.setCellValue("收货人座机");
//            cell = titleRow.createCell(10);
//            cell.setCellValue("邮箱地址");
//            cell = titleRow.createCell(11);
//            cell.setCellValue("汇款人姓名");
//            for (int i = 0; i < byIdList.size(); i++) {
//                OrderAndReceiver orderAndReceiver = byIdList.get(i);
//                //数据行
//                titleRow = sheet.createRow(i + 1);
//                //订单编号
//                cell = titleRow.createCell(0);
//                cell.setCellValue(orderAndReceiver.getId());
//                cell = titleRow.createCell(1);
//                cell.setCellValue(orderAndReceiver.getOrderType());
//                cell = titleRow.createCell(2);
//                cell.setCellValue(orderAndReceiver.getBusinessType());
//                cell = titleRow.createCell(3);
//                cell.setCellValue(orderAndReceiver.getDeliveryStyle());
//                cell = titleRow.createCell(4);
//                cell.setCellValue(orderAndReceiver.getOrderStatus());
//                cell = titleRow.createCell(5);
//                cell.setCellValue(orderAndReceiver.getCreateTime());
//                cell = titleRow.createCell(6);
//                cell.setCellValue(orderAndReceiver.getReceiverName());
//                cell = titleRow.createCell(7);
//                cell.setCellValue(orderAndReceiver.getReceiverAdress());
//                cell = titleRow.createCell(8);
//                cell.setCellValue(orderAndReceiver.getReceiverTelephone());
//                cell = titleRow.createCell(9);
//                cell.setCellValue(orderAndReceiver.getReceiverPhone());
//                cell = titleRow.createCell(10);
//                cell.setCellValue(orderAndReceiver.getReceiverEmail());
//                cell = titleRow.createCell(11);
//                cell.setCellValue(orderAndReceiver.getPayName());
//            }
//
//            //该订单的商品 创建sheet2
//            Sheet sheet2 = workbook.createSheet("订单商品表");
//            //创建行
//            Row titleRow1 = sheet2.createRow(0);
//            //2.此行创建标题列
//            Cell cell2 = titleRow1.createCell(0);
//
//            cell2.setCellValue("商品编号");
//            cell2 = titleRow1.createCell(1);
//
//            cell2.setCellValue("商品名称");
//            cell2 = titleRow1.createCell(2);
//
//            cell2.setCellValue("商品单价");
//            cell2 = titleRow1.createCell(3);
//
//            cell2.setCellValue("商品数量");
//            cell2 = titleRow1.createCell(4);
//
//            for (int i = 0; i < orderGoodByOrderIdList.size(); i++) {
//                System.out.println(orderGoodByOrderIdList.size());
//                OrderGoodVo orderGoodVo = orderGoodByOrderIdList.get(i);
//                //数据行
//                titleRow1 = sheet2.createRow(i + 1);
//                //商品编号
//                cell2 = titleRow1.createCell(0);
//                cell2.setCellValue(orderGoodVo.getGoodsId());
//                //商品名称
//                cell2 = titleRow1.createCell(1);
//                cell2.setCellValue(orderGoodVo.getOrderProductName());
//                //商品单价
//                cell2 = titleRow1.createCell(2);
//                cell2.setCellValue(String.valueOf(orderGoodVo.getOrderProductPrice()));
//                //购买商品数量
//                cell2 = titleRow1.createCell(3);
//                cell2.setCellValue(orderGoodVo.getOrderProductNumber());
//            }
//            workbook.write(fileOutputStream);
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                if (fileOutputStream != null) fileOutputStream.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        return AxiosResult.success(true);
//    }
}
